﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using Framework.Graphics;
using Framework.Graphics.Light.Shadow;
using Framework.GameStateManagment;
using Framework.GameObjectManagment;
using Framework.GameObjectManagment.GameObjects;

namespace Framework.GameObjectManagment.GameObjects
{
    class BaseEnemy : GameObject
    {
        int _life;
        Texture2D _back, _front;
        Vector2 _position, _target;
        SpriteFont _sf;

        public Vector2 Target
        {
            get { return _target; }
            set { _target = value; }
        }

        public override void Init()
        {
            base.Init();

            _position = new Vector2(100, 100); // default position
            _life = 100; // default lifes
            _target = new Vector2(512, 362) + new Vector2(50,50);


        }

        public override void LoadContent(ContentManager content)
        {
            _back = content.Load<Texture2D>(@"GameObject/Enemy/Enemy1-Ground");
            _front = content.Load<Texture2D>(@"GameObject/Enemy/Enemy1-Body");

            _sf = content.Load<SpriteFont>(@"Font/Font");

            Init();

            base.LoadContent(content);
        }

        public override void Update()
        {
            Random Rd = new Random();
            _position = new Vector2(400, 100); // test
            
            base.Update();
        }

        public override void Draw()
        {
            base.Draw();

            // double angle = Math.Atan2(362 + 50 - Framework.GameStateManagment.Input.MS.Y,
            // 512 + 50 - Framework.GameStateManagment.Input.MS.X);
            // Eigene Position - Ziel Position

            double rotation = Math.Atan2(_position.Y+50 - _target.Y +Input.AllMovement.Y,
            _position.X+50- _target.X +Input.AllMovement.X) - MathHelper.ToRadians(90);

            //float rotation = (float)Math.Atan2(_position.Y + 50 - (_target.Y + Input.AllMovement.Y), _position.X + 50- (_target.X + Input.AllMovement.X));

            //double rotation = (float)Math.Atan2(_position.Y - _target.Y,_position.X - _target.X);


            Camera.TryDraw(_back, _position + Input.AllMovement , null, Color.White, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0f);
            Camera.TryDraw(_front, _position +  new Vector2(50,50)+Input.AllMovement, null, Color.White, (float)rotation, new Vector2(_front.Width/2), 0.5f, SpriteEffects.None, 0f);


            //Camera.SpriteBatch.DrawString(_sf, Convert.ToString(MathHelper.ToDegrees((float)rotation)), new Vector2(500, 500), Color.Red);
            //Camera.SpriteBatch.DrawString(_sf, Convert.ToString((rotation)), new Vector2(650, 500), Color.Red);

            Camera.SpriteBatch.DrawString(_sf, Convert.ToString(Input.AllMovement.X) + "  |  " + Convert.ToString(Input.AllMovement.Y), new Vector2(500, 530), Color.Red);
        }

        public override void DrawShadows(LightArea LA)
        {
            Camera.TryDraw(_back, LA.ToRelativePosition(_position + Input.AllMovement), null, Color.White, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0f);
            base.DrawShadows(LA);
        }
    }
}
